var systemUserOperationStatisticsParam=null;
var g_totalNum = 1000000;
$(document).ready(function(){	
		
		$('#ComboxSearchOperation').combobox({
			url:BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_USER_OPERATION  + '&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable: false,
		    method:'get',
		    loadFilter: function(data){
		    	var allCheck = {'valueCode':'','valueName':'全部'};
		    	data.unshift(allCheck);
		    	return data;
		    }
		});
		
		$("#datagrid").datagrid({
			url : BASE_URL_USER_LOG + '/statistics/forUserOPT' + '?v=' + Math.random(),
			method:'get',
			autoRowHeight:true,
			nowrap:false,
			singleSelect:true,
			striped:true,
			pageSize:20,
			pageList:[5,10,20,50,100],
			columns:[[
						{field:'person',title:'操作人',width:100,align:'left'},
						{field:'user',title:'操作账号',width:70,align:'left'},
						{field:'oPTType',title:'操作',width:80},
						{field:'optAmount',title:'次数',width:80}
			      ]],
			pagination:true,
			onSelect:function(rowIndex,rowData){
				$("#toolbar_edit").linkbutton('enable');
				$("#toolbar_delete").linkbutton('enable');
				 $(this).datagrid('unselectRow', rowIndex);
			},
			loadFilter:function(data){
				//alert("inData:"+JSON.stringify(data));
				var pageRowSize = $("#datagrid").datagrid("options").pageSize;
				var pageNumber = $("#datagrid").datagrid("options").pageNumber;
				if(data.content && data.content.length > 0)
				{
					if(data.content.length < pageRowSize)
					{
						//修正总数为正确的总记录数
						g_totalNum = pageRowSize * (pageNumber - 1) + data.content.length;
					}
					else
					{
						g_totalNum = g_totalNum > pageRowSize * pageNumber? g_totalNum:pageRowSize * (pageNumber + 1);
					}
				}
				else 
				{
					if(pageNumber > 1)
					{
						$.messager.alert('提示','<p>所输入页码数超出数据范围，请修正页码数!</p>','info');
					}
					g_totalNum = g_totalNum < pageRowSize * pageNumber? g_totalNum:pageRowSize * pageNumber;
				}
				return {
					total: g_totalNum,
					rows: data.content
				};
			},
			onLoadSuccess: function(data) {
				//将表格里的html编码还原成原始字符，用于表单显示
				var rowDatas = $.data($("#datagrid")[0],"datagrid").data.rows;			
				$.data($("#datagrid")[0],"datagrid").data.rows = JSON.parse(JSON.stringify(rowDatas).replace(/&lt;/g, "<").replace(/&gt;/g, ">"));
				$(".pagination-info").html("当前显示" + rowDatas.length +　"条记录");
			},
			onBeforeLoad:function(param){
				g_totalNum = 1000000;
				param.page -= 1;
				param.size = param.rows;
				delete param.rows;
				
				var optPerson = $('#txtSearchOperator').val();
				if(optPerson !== ''){
					//alert("getText:"+fieldName);
						param.optPerson = optPerson;
				}
				
				var optType = $('#ComboxSearchOperation').combobox('getValue');
				if(optType !== '全部' && optType !== ''){
					//alert("getText:"+fieldName);
						param.optType = optType;
				}
				 
				 var beginOfCreateTime = $('#txtBeginTime').datetimebox('getValue');
				if(beginOfCreateTime !== ''){
					param.beginOfCreateTime = beginOfCreateTime;
				}
				
				var endOfCreateTime = $('#txtEndTime').datetimebox('getValue');
				if(endOfCreateTime !== ''){
					param.endOfCreateTime = endOfCreateTime;
				} 
				
				systemUserOperationStatisticsParam = param;
			}
		});
		
		$("#datagrid").datagrid('getPager').pagination({   
			displayMsg:'当前显示从 [{from}] 到 [{to}]',
		    layout: ['list', 'sep', 'prev', 'sep', 'manual', 'sep', 'next', 'sep', 'refresh'],
		    afterPageText: "页",
		    onChangePageSize: function(pageSize) {
		    	//$("#datagrid").datagrid("options").pageSize = pageSize;
		    	$(this).pagination('options').pageNumber = 1;
		    }
		}); 

});
	
	/*//对于时间格式的转换 
	$.fn.datebox.defaults.formatter = function(date) { 
		var y = date.getFullYear();
		var m = fullnum(date.getMonth() + 1);
		var d = fullnum(date.getDate());
		return y + '-' + m + '-' + d;
	};
	
	function fullnum(obj) { //对于月小于10格式的转换,因为Timestamp转换必须是2013-01-04这种格式 
		if (Number(obj) < 10) {
			return '0' + obj;
		} else {
			return obj;
		}
	}*/
	
	//查询
	function search(){
		dataRetrieval('#txtBeginTime', '#txtEndTime');
	}
	function exportData()
	{
		$("#datagrid").datagrid("reload", BASE_URL_USER_LOG + '/statistics/forUserOPT' + '?v=' + Math.random());
		var param = JSON.stringify(systemUserOperationStatisticsParam);
		location.href= BASE_URL_EXPORTDATA_FILE + '/userOperationStatisticsExport?param='+param;
	}